package com.hx.util.mail;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class SendMailController implements Controller {
	private SimpleMailMessage message;
	private MailEngine engine;

	public void setMessage(SimpleMailMessage message) {
		this.message = message;
	}

	public void setEngine(MailEngine engine) {
		this.engine = engine;
	}

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		User user = new User();
		//message.setTo(user.getName() + "<" + user.getEmail() + ">");
	

		Map<String, Object> model = new HashMap<String, Object>();
		model.put("user", user);

		// Vilocity模板
		engine.send(message, "regist.vm", model);
		// FreeMaker模板
		// engine.send(message, "test.ftl", model);

		return new ModelAndView("sendMail.jsp");
	}
}
